package ioperation;

import book.Book;
import book.BookList;
import exception.ReturnException;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    @Override
    public void work(BookList bookList) throws ReturnException {
        System.out.println("请输入想归还的书名：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        for (int i = 0; i < bookList.getUsedsize(); i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)){
                if(book.isIsborrow()){
                    book.setIsborrow(false);
                    System.out.println("归还成功！！");
                    return;
                }else {
                    throw new ReturnException("该图书未被借出....");
                }
            }
        }
        throw new ReturnException("该图书不存在.....");
    }
}
